var http = require('http');
var template = require('art-template');
var fs = require('fs');

var server = http.createServer();

var wwwDir = 'E:/documents/QQ';

server.on('request', function(req, resp) {
  var url = req.url;
  
  fs.readFile('./data/template.html', function(err, data) {
    if (err) {
      console.log('File Not Found');
    }
	
	fs.readdir(wwwDir, function(err, files) {
      if (err) {
	    return resp.end('File Not Found.');
	  }
      var ret = template.render(data.toString(), {
		wwwDir,
		files
	  });
	  resp.end(ret);
	});
  });
});

server.listen(3000, function() {
  console.log('running...');
});
